package com.leetcode.algorithm.y22.m07;

import com.leetcode.algorithm.common.TreeNode;

/**
 * 101. 对称二叉树
 * 
 * https://leetcode.cn/problems/symmetric-tree/
 * 
 * @author jie.deng
 *
 */
public class Question0101Solution01 {

	public boolean isSymmetric(TreeNode root) {
		return isSymmetric(root.left, root.right);
	}

	private boolean isSymmetric(TreeNode left, TreeNode right) {
		if (left == null && right == null) {
			return true;
		}
		if (left == null || right == null) {
			return false;
		}
		if (left.val != right.val) {
			return false;
		}
		return isSymmetric(left.left, right.right) && isSymmetric(left.right, right.left);
	}

}